<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./axios.min.js"></script>
    <script src="./jquery-3.5.0.min.js"></script>
    <script>
        //1.全局默认配置
        let token='eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiJOUT09Iiwic3ViIjoiYWRtaW4xIiwiaXNzIjoiMDk4ZjZiY2Q0NjIxZDM3M2NhZGU0ZTgzMjYyN2I0ZjYiLCJpYXQiOjE2MDIyMDg5NjQsImF1ZCI6InJlc3RhcGl1c2VyIiwiZXhwIjoxNjAyMzgxNzY0LCJuYmYiOjE2MDIyMDg5NjR9.y7ri9xTZSz3AqF9iY81GDbc4JAoagxYsrfo_uSb9Lhs'
        axios.defaults.baseURL = 'http://123.57.30.43:7788'; 
        axios.defaults.headers.common['Authorization'] =token; 
        axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; 
        //2.响应拦截
        axios.interceptors.response.use(function (response) { 
                // 对响应数据做点什么 
                if(response.data.status==200){
                    return response.data
                }else{
                    alert(response.data.message);
                    return Promise.reject(response.data); 
                    // return response.data.message
                }
                // return response; 
            },
        function (error) { 
                // 对响应错误做点什么 
                // alert(error.data.message)
                return Promise.reject(error); 
        });
        //3.封装函数
        var request={
            get:function(url,params){
                return axios.get(url,{
                    params
                })
            },
            post:function(url,data){
                return axios.post(url,$.param(data))
            },
            postJSON:function(url,data){
                return axios.post(url,data,{
                    headers:{
                        'Conten-tType': "application/json;"
                    }
                })
            }
        }
        //4.发送请求，处理数据
          //1.请求所有栏目-get
        //   request.get('/category/findAll').then(response=>{
        //       console.log(response)
        //   })
          //2.根据分页查询用户信息-get-参数
        //   request.get('/baseUser/pageQuery',{
        //       page:1,
        //       pageSize:10
        //   }).then(response=>
        //   console.log(response))
          //3.请求保存或更新-post-参数为query类型
        //   var data={
        //       username:'terry-02',
        //       password:'terry',
        //       gender:'men'
        //   }
        //   request.post('/baseUser/saveOrUpdate',data).then(response=>{
        //       console.log(response)
        //   })
          //4.login-post请求-JSON格式
          var login={
              username:'admin1',
              password:'123321'
          }
          request.postJSON("/user/login",login).then(response=>{
              console.log(response)
          })
    </script>
</head>
<body>
    
</body>
</html>